#if APP_DRAWWAVE

#include "drawwavepaper.h"
#include "stdio.h"

DrawWavePaper::DrawWavePaper(QWidget *parent) :
    QWidget(parent)
{
    Magnification=ZOOM_1X;
}

DrawWavePaper::~DrawWavePaper()
{
    //do nothing!!
}

void DrawWavePaper::setRange(float min, float max)
{
    Range_Min=min;
    Range_Max=max;
}

void DrawWavePaper::setMagnification(MAGNIFICATION d)
{
    Magnification=d;
    update();
}

void DrawWavePaper::Draw(float d)
{
    datalist.append(d);
    update();
}

void DrawWavePaper::Clear()
{
    datalist.clear();
    update();
}

void DrawWavePaper::paintEvent(QPaintEvent */*event*/)
{
    int i=0;
    int X_points=0;
    int count=0;
    int x1=0,y1=0,x2=0,y2=0;
    QPainter painter(this);
    painter.setRenderHint(QPainter::Antialiasing, true);
    painter.setPen(QColor(255,255,255));

    count=datalist.count();
    if(Magnification==ZOOM_BEST)
        X_d=width()/count;
    else
        X_d=DEFAULT_XD*Magnification;
    Y_d=height()/(Range_Max-Range_Min);

    X_points=width()/X_d;

    if(count<X_points){
        for(i=1;i<count;i++){
            x1=(i-1)*X_d;
            y1=datalist.at(i-1);
            x2=i*X_d;
            y2=datalist.at(i);
            painter.drawLine(x1,y1,x2,y2);
        }
    }
    else{
        count=count%X_points;
        for(i=count+1;i<count;i++){
            x1=(i-count-1)*X_d;
            y1=datalist.at(i-1);
            x2=(i-count)*X_d;
            y2=datalist.at(i);
            painter.drawLine(x1,y1,x2,y2);
        }
    }
    printf("x1:%d,y1:%d,x2:%d,y2:%d\n",x1,y1,x2,y2);
}

#endif
